//
//  ViewController.m
//  Moving Stuff
//
//  Created by iD Student on 7/9/13.
//  Copyright (c) 2013 jasonkurtzman. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    gameTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(gameUpdate) userInfo:nil repeats:YES];
    
    //Animtaions
    upAnimation = [[NSMutableArray alloc] init];
    downAnimation = [[NSMutableArray alloc] init];
    rightAnimation = [[NSMutableArray alloc] init];
    leftAnimation = [[NSMutableArray alloc] init];
    
    //Up Anims
    [upAnimation addObject:[UIImage imageNamed:@"up1.png"]];
    [upAnimation addObject:[UIImage imageNamed:@"up2.png"]];
    [upAnimation addObject:[UIImage imageNamed:@"up3.png"]];
    
    //Down Anims
    [downAnimation addObject:[UIImage imageNamed:@"down1.png"]];
    [downAnimation addObject:[UIImage imageNamed:@"down2.png"]];
    [downAnimation addObject:[UIImage imageNamed:@"down3.png"]];
    
    //Right Anims
    [rightAnimation addObject:[UIImage imageNamed:@"right1.png"]];
    [rightAnimation addObject:[UIImage imageNamed:@"right2.png"]];
    [rightAnimation addObject:[UIImage imageNamed:@"right3.png"]];
    
    //Left Anims
    [leftAnimation addObject:[UIImage imageNamed:@"left1.png"]];
    [leftAnimation addObject:[UIImage imageNamed:@"left2.png"]];
    [leftAnimation addObject:[UIImage imageNamed:@"left3.png"]];
    
    gameTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(gameUpdate) userInfo:nil repeats:YES];
}

-(IBAction)upPressed:(id)sender
{
    goingUp = YES;
    movingImage.animationImages = upAnimation;
    [movingImage startAnimating];
}
-(IBAction)downPressed:(id)sender
{
    goingDown = YES;
    movingImage.animationImages = downAnimation;
    [movingImage startAnimating];
}
-(IBAction)leftPressed:(id)sender
{
    goingLeft = YES;
    movingImage.animationImages = leftAnimation;
    [movingImage startAnimating];
}
-(IBAction)rightPressed:(id)sender
{
    goingRight = YES;
    movingImage.animationImages = rightAnimation;
    [movingImage startAnimating];
}
-(IBAction)buttonReleased:(id)sender
{
    goingUp = NO;
    goingDown = NO;
    goingLeft = NO;
    goingRight = NO;
    
    [movingImage stopAnimating];
}

-(void)gameUpdate
{
    if(goingUp == YES)
    {
        CGPoint oldCenter = movingImage.center;
        movingImage.center = CGPointMake(oldCenter.x, oldCenter.y - 3);
    }
    else if(goingDown == YES)
    {
        CGPoint oldCenter = movingImage.center;
        movingImage.center = CGPointMake(oldCenter.x, oldCenter.y + 3);
    }
    else if(goingRight == YES)
    {
        CGPoint oldCenter = movingImage.center;
        movingImage.center = CGPointMake(oldCenter.x + 3, oldCenter.y);
    }
    else if(goingLeft == YES)
    {
        CGPoint oldCenter = movingImage.center;
        movingImage.center = CGPointMake(oldCenter.x - 3, oldCenter.y);
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
